/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Validation;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

/**
 *
 * @author sunwei
 */
public class ProductQuantityInputValidator implements Validator {

    @Override
    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {

        long p1 = (Long) component.getAttributes().get("quantity1");
        long p2 = (Long) component.getAttributes().get("quantity2");
        long p3 = (Long) component.getAttributes().get("quantity3");
        long p4 = (Long) value;

        if (p1 == 0 && p2 == 0 && p3 == 0 && p4 == 0) {
            throw new ValidatorException(new FacesMessage("Please input quantity for at least one product type"));
        }
    }
}
